layui.use('table', function () {
    let table = layui.table;
    let form = layui.form;
    let $ = layui.jquery;

    table.render({
        elem: '#destroyer',
        url: '/chaser/findChaser',
        page: true,
        height: '500px',
        cols: [
            [
                {
                    field: 'formation',
                    title: "编队名称",
                    align: 'center',
                    sort: true
                },
                {
                    field: 'helicopterNumber',
                    title: "直升机数量",
                    align: 'center'
                },
                {
                    field: 'destroyerNumber',
                    title: "驱逐舰数目",
                    align: 'center'
                },
                {
                    field: 'frigateNumber',
                    title: '护卫舰数目',
                    align: "center"
                },
                {
                    field: 'supplyShipNumber',
                    title: '补给舰数目',
                    align: "center"
                },
                {
                    field: 'submarineChaserNumber',
                    title: '猎潜艇数目',
                    align: "center"
                },
                {
                    title: '操作',
                    align: 'center',
                    toolbar: '#barEdit'
                }
            ]
        ],
        limits: [1, 3, 5, 7, 9],
        limit: 3,
        done: function (res, curr, count) {
            $("[lay-id='destroyer']>.layui-table-page").css({
                "text-align": "center"
            });
        }
    });

    table.on('tool(pageTable)', function (obj) {
        let data = obj.data,
            layEvent = obj.event;
        switch (layEvent) {
            case 'state':
                $.post('/helicopter/findById', {"id": data.formationId}, (result) => {
                    if (result.state == 200) {
                        $(result.data).each((index, value) => {
                            layer.msg('型号：' + value.type + '    直升机数量数量：' + value.number + '  驱逐舰数目；' + data.destroyerNumber + '  护卫舰数目:' + data.frigateNumber + '  补给舰数目:' + data.supplyShipNumber + '  猎潜艇数目:' + data.submarineChaserNumber, {
                                icon: 1,
                                time: 3000
                            });
                        });
                    } else {
                        layer.msg(result.message, {
                            icon: 2,
                            time: 3000
                        });
                    }
                })
                break;
        }
    });
});